import { EventEmitter } from 'events';
import * as THREE from 'three';


export default class Time extends EventEmitter {
    constructor(){
        super();
        this.start = Date.now();
        this.current = this.start;
        this.delta = 16;
        this.elapsed = 0;
        this.clock = new THREE.Clock();
        this.update();
    }
    update(){
        // console.log(this.clock.getDelta()); 0.016 
        let currentTime = Date.now();
        this.delta = currentTime - this.current;
        this.current = currentTime;
        this.elapsed = this.current - this.start;
        this.emit('update');
        window.requestAnimationFrame(this.update.bind(this));
    }
}